Ext.define('Editor.controller.NewWindow', {
    extend: 'Ext.app.Controller',
    
    views: [
        'Editor.view.NewWindow'
    ],
    
    init: function(){
        // ...
        
        this.control({
            'newwindow checkboxfield[prefix]': {
                change: function(ckb){
                    this.enablePropriety(ckb);
                }
            },
            
            'newwindow button[action=gencode]' : {
                click: this.genCode
            },
            
            'newwindow button[action=create]' : {
                click: this.createCmp
            },
            
            'newwindow button[action=getprop]' : {
                click: function (cmp){
                    var me = this;
                    me.getProp(cmp);
                }
            },
            
        });
    },
    
    enablePropriety : function(cmp){
        var prop = cmp.next();
        if(prop.isDisabled()){
            prop.setDisabled(false);
        }
        else {
            prop.setDisabled(true);
        }
        //console.log('checkbox "include" change status');
    },
    
    getProp: function(cmp){
        var form = cmp.up('newwindow');
        function e(el, i, ar){
            // pour empecher de recupere les checkbox (include)
            el.setDisabled(!el.isDisabled());
        };
        
        var ckbs = form.query('checkboxfield[prefix=include]');
        ckbs.forEach(e);
        var vals = form.getForm().getValues();
        //console.log(vals);
        ckbs.forEach(e);
        
        if(vals.items){
            console.log('if (vals.items) items: ', vals.items, typeof(vals.items), eval("(" + vals.items + ")"));
            
            var tmp = eval("(" + vals.items + ")");
            // console.log('tmp', tmp);
            vals.items = [];
            vals.items.push(tmp);
            // console.log(vals.items);
        }
        
        console.log(vals);
        return vals;
    },
    
    genCode: function(cmp){
        var me = this;
        var v = JSON.stringify(me.getProp(cmp));
        //console.log(v);
        return v;
    },
    
    createCmp: function(cmp){
        var me = this;
        Ext.create('Ext.window.Window', JSON.parse(me.genCode(cmp))/*me.getProp(cmp)*/);
    }
});
